package com.venutech.gongan.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.utils.PageUtils;
import com.venutech.gongan.common.Constants;
import com.venutech.gongan.dao.*;
import com.venutech.gongan.dto.rpc.common.TempEquipBindingWorkFilterProperties;
import com.venutech.gongan.dto.rpc.common.vo.PoleDto;
import com.venutech.gongan.entity.*;
import com.venutech.gongan.service.JkgwService;
import com.venutech.gongan.service.SpGrantService;
import com.venutech.gongan.service.UserService;
import com.venutech.gongan.service.WorkService;
import com.venutech.gongan.util.NumberUtil;
import com.venutech.gongan.vo.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;

//import com.venutech.imd.common.Constants;
//import com.venutech.imd.common.TempEquipBindingWorkFilterProperties;
//import com.venutech.imd.dao.*;
//import com.venutech.imd.dto.rpc.common.vo.*;
//import com.venutech.imd.entity.*;
//import com.venutech.imd.service.JkgwService;
//import com.venutech.imd.service.SpGrantService;
//import com.venutech.imd.service.UserService;
//import com.venutech.imd.service.WorkService;
//import com.venutech.imd.util.NumberUtil;

@EnableConfigurationProperties({TempEquipBindingWorkFilterProperties.class})
@Service
public class JkgwServiceImpl implements JkgwService {
    private Logger logger = LoggerFactory.getLogger(JkgwServiceImpl.class);

    @Resource
    private JkgwMapper jkgwMapper;
    @Resource
    private EquipmenMapper equipmenMapper;
    @Resource
    private QdsxjMapper qdsxjMapper;
    @Resource
    private QRCodeMapper qrCodeMapper;
    @Resource
    private OpWorkMapper opWorkMapper;
    @Resource
    private SpGrantMapper spGrantMapper;
    @Autowired
    private SpGrantService spGrantService;
    @Autowired
    private PoleQrCodeBindHistoryMapper poleQrCodeBindHistoryMapper;
    @Autowired
    private EquipBindingWorkMapper equipBindingWorkMapper;
    @Autowired
    private TempEquipBindingWorkFilterProperties tempEquipBindingWorkFilterProperties;

    @Autowired
    private WorkMapper workMapper;

    @Autowired
    private WorkService workService;

    @Autowired
    private UserService userService;

    @Override
    public int insert(Jkgw jkgw) {
        return jkgwMapper.insert(jkgw);
    }

    @Override
    public int getLastSeq() {
        return jkgwMapper.getLastSeq();
    }

    @Override
    public int updateJkgw(Jkgw jkgw) {
        return jkgwMapper.updateJkgw(jkgw);
    }

    @Override
    public int deleteById(Integer gw_id) {
        return jkgwMapper.deleteById(gw_id);
    }

    @Override
    public Jkgw getById(Integer gw_id) {
        return jkgwMapper.getById(gw_id);
    }

    /* @Override
     public int updateJkgwRadius(Integer gw_id) {
         return jkgwMapper.updateJkgwRadius(gw_id);
     }
 */
    //api
    @Override
    public Jkgw getByQrId(Integer qr_id) {
        return jkgwMapper.getByQrId(qr_id);
    }

    //api
    @Override
    public int insertPoleDto(PoleDto poleDto) {
        Jkgw jkdw = assembleJkgw(poleDto);
        return jkgwMapper.insert(jkdw);
    }

    @Override
    public PoleEquipmentDto getEquipment(Integer qr_id) {
        //通过二维码查杆件信息
        Jkgw jkgw = jkgwMapper.getByQrId(qr_id);
        if (Objects.isNull(jkgw)) {
            return null;
        }

        //从关联表TB_EQUIPMEN里 根据qrid查询多个设备id
        List<Integer> list = equipmenMapper.getByQrId(qr_id);
        //从设备表查询设备ID和名称
        List<QdsxjDto> qdsxjList = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            int sb_id = list.get(i);
            QdsxjDto qdsxj = new QdsxjDto();
            Qdsxj sxj = qdsxjMapper.getById(sb_id);
            if (Objects.nonNull(sxj)) {
                qdsxj.setSb_id(sxj.getSb_id());
                qdsxj.setSb_name(sxj.getSb_name());
                qdsxj.setSb_jd(sxj.getSb_jd());
                qdsxj.setSb_wd(sxj.getSb_wd());
                //qdsxj.setSb_xzqy(sxj.getSb_xzqy());    // 增加行政区域编码
                OpWork opWork = opWorkMapper.getByDevCode(sxj.getSb_bm());
                if (Objects.nonNull(opWork)) {
                    EquipmentOpStatus equipmentOpStatus = new EquipmentOpStatus();
                    equipmentOpStatus.setGbid(opWork.getDev_code());
                    equipmentOpStatus.setFaultType(opWork.getFault_type());
                    equipmentOpStatus.setFaultRemark(opWork.getFault_remark());
                    equipmentOpStatus.setReportTime(opWork.getFault_time());
                    equipmentOpStatus.setRepairStatus(opWork.getRepair_status());
                    qdsxj.setEquipmentOpStatus(equipmentOpStatus);
                }
                qdsxjList.add(qdsxj);
            }
        }
        PoleEquipmentDto poleEquipmentDto = new PoleEquipmentDto();
        poleEquipmentDto.setGw_id(jkgw.getGw_id());
        poleEquipmentDto.setGw_bw(jkgw.getGw_bw());
        poleEquipmentDto.setGw_jd(jkgw.getGw_jd());
        poleEquipmentDto.setGw_name(jkgw.getGw_name());
        poleEquipmentDto.setGw_wd(jkgw.getGw_wd());
        poleEquipmentDto.setGw_zx(jkgw.getGw_zx());
        poleEquipmentDto.setGw_wz(jkgw.getGw_wz());
        poleEquipmentDto.setArea_code(jkgw.getArea_code());
        poleEquipmentDto.setArea_name(jkgw.getArea_name());
        poleEquipmentDto.setTown_code(jkgw.getTown_code());
        poleEquipmentDto.setTown_name(jkgw.getTown_name());
        //根据区域编码、小类型编码返回名称
        //根据qrid查询区域编码、小类型编码
        String qyName = qrCodeMapper.getQyName(qr_id);
        String xlxBm = qrCodeMapper.getQyXlxBm(qr_id);

        poleEquipmentDto.setQybm(qyName);
        poleEquipmentDto.setXlxbm(xlxBm);
        poleEquipmentDto.setQdsxjDtoList(qdsxjList);

        return poleEquipmentDto;
    }

    @Override
    public PoleEquipmentDto getEquipmentForMonitorType(Integer qr_id) {
//通过二维码查杆件信息
        Jkgw jkgw = jkgwMapper.getByQrId(qr_id);
        if (Objects.isNull(jkgw)) {
            return null;
        }

        //从关联表TB_EQUIPMEN里 根据qrid查询多个设备id
        List<Integer> list = equipmenMapper.getByQrId(qr_id);
        //从设备表查询设备ID和名称
        List<QdsxjDto> qdsxjList = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            int sb_id = list.get(i);
            QdsxjDto qdsxj = new QdsxjDto();
            Qdsxj sxj = qdsxjMapper.getByIdForMontorType(sb_id);
            if (Objects.nonNull(sxj)) {
                qdsxj.setSb_id(sxj.getSb_id());
                qdsxj.setSb_name(sxj.getSb_name());
                qdsxj.setSb_jd(sxj.getSb_jd());
                qdsxj.setSb_wd(sxj.getSb_wd());
                //qdsxj.setSb_xzqy(sxj.getSb_xzqy());    // 增加行政区域编码
                OpWork opWork = opWorkMapper.getByDevCode(sxj.getSb_bm());
                if (Objects.nonNull(opWork)) {
                    EquipmentOpStatus equipmentOpStatus = new EquipmentOpStatus();
                    equipmentOpStatus.setGbid(opWork.getDev_code());
                    equipmentOpStatus.setFaultType(opWork.getFault_type());
                    equipmentOpStatus.setFaultRemark(opWork.getFault_remark());
                    equipmentOpStatus.setReportTime(opWork.getFault_time());
                    equipmentOpStatus.setRepairStatus(opWork.getRepair_status());
                    qdsxj.setEquipmentOpStatus(equipmentOpStatus);
                }
                qdsxjList.add(qdsxj);
            }
        }
        PoleEquipmentDto poleEquipmentDto = new PoleEquipmentDto();
        poleEquipmentDto.setGw_id(jkgw.getGw_id());
        poleEquipmentDto.setGw_bw(jkgw.getGw_bw());
        poleEquipmentDto.setGw_jd(jkgw.getGw_jd());
        poleEquipmentDto.setGw_name(jkgw.getGw_name());
        poleEquipmentDto.setGw_wd(jkgw.getGw_wd());
        poleEquipmentDto.setGw_zx(jkgw.getGw_zx());
        poleEquipmentDto.setGw_wz(jkgw.getGw_wz());
        poleEquipmentDto.setArea_code(jkgw.getArea_code());
        poleEquipmentDto.setArea_name(jkgw.getArea_name());
        poleEquipmentDto.setTown_code(jkgw.getTown_code());
        poleEquipmentDto.setTown_name(jkgw.getTown_name());
        //根据区域编码、小类型编码返回名称
        //根据qrid查询区域编码、小类型编码
        String qyName = qrCodeMapper.getQyName(qr_id);
        String xlxBm = qrCodeMapper.getQyXlxBm(qr_id);

        poleEquipmentDto.setQybm(qyName);
        poleEquipmentDto.setXlxbm(xlxBm);
        poleEquipmentDto.setQdsxjDtoList(qdsxjList);

        return poleEquipmentDto;
    }

    /**
     * 查询杆件信息带设备列表及用户视频查看权限
     *
     * @param qr_id
     * @param user
     * @return
     */
    @Override
    public PoleEquipmentDto getEquipment(Integer qr_id, User user) {
        //通过二维码查杆件信息

        Jkgw jkgw = jkgwMapper.getByQrId(qr_id);
        if (Objects.isNull(jkgw)) {
            return null;
        }

        if (Objects.nonNull(jkgw.getGw_jd())) {
            jkgw.setLongitude(NumberUtil.formatNumber(jkgw.getGw_jd()));
        }
        if (Objects.nonNull(jkgw.getGw_wd())) {
            jkgw.setLatitude(NumberUtil.formatNumber(jkgw.getGw_wd()));
        }

        //从关联表TB_EQUIPMEN里 根据qrid查询多个设备id
        List<Integer> list = equipmenMapper.getByQrId(qr_id);
        //从设备表查询设备ID和名称
        List<QdsxjDto> qdsxjList = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            int sb_id = list.get(i);
            QdsxjDto qdsxjDto = new QdsxjDto();
            Qdsxj sxj = qdsxjMapper.getById(sb_id);
            if (sxj == null) {
                continue;
            }
            qdsxjDto.setSb_id(sxj.getSb_id());
            qdsxjDto.setSb_name(sxj.getSb_name());
            qdsxjDto.setSb_bm(sxj.getSb_bm());

            OpWork opWork = opWorkMapper.getByDevCode(sxj.getSb_bm());
            if (Objects.nonNull(opWork)) {
                EquipmentOpStatus equipmentOpStatus = new EquipmentOpStatus();
                equipmentOpStatus.setGbid(opWork.getDev_code());
                equipmentOpStatus.setFaultType(opWork.getFault_type());
                equipmentOpStatus.setFaultRemark(opWork.getFault_remark());
                equipmentOpStatus.setReportTime(opWork.getFault_time());
                equipmentOpStatus.setRepairStatus(opWork.getRepair_status());
                qdsxjDto.setEquipmentOpStatus(equipmentOpStatus);
            }

            // 监控设备的视频权限
            List<String> videoPrivileges = new ArrayList<>();
            videoPrivileges.add(sxj.getSb_xzqy());
            if (spGrantService.checkGrantedVideoPrivilege(user.getUser_id(), sxj.getSb_xzqy())) {
                logger.info("getEquipment: put user area_code to video privis: {}, sxj.sb_name={}", user.getUser_area(), sxj.getSb_name());
                videoPrivileges.add(user.getUser_area());
            }
            qdsxjDto.setVideoPrivileges(videoPrivileges);

            qdsxjList.add(qdsxjDto);
        }
        PoleEquipmentDto poleEquipmentDto = new PoleEquipmentDto();
        poleEquipmentDto.setGw_id(jkgw.getGw_id());
        poleEquipmentDto.setGw_bw(jkgw.getGw_bw());
        poleEquipmentDto.setGw_jd(jkgw.getGw_jd());
        poleEquipmentDto.setGw_name(jkgw.getGw_name());
        poleEquipmentDto.setGw_wd(jkgw.getGw_wd());
        poleEquipmentDto.setGw_zx(jkgw.getGw_zx());
        poleEquipmentDto.setGw_wz(jkgw.getGw_wz());
        poleEquipmentDto.setArea_code(jkgw.getArea_code());
        poleEquipmentDto.setArea_name(jkgw.getArea_name());
        poleEquipmentDto.setLongitude(jkgw.getLongitude());
        poleEquipmentDto.setLatitude(jkgw.getLatitude());
        //根据区域编码、小类型编码返回名称
        //根据qrid查询区域编码、小类型编码
        String qyName = qrCodeMapper.getQyName(qr_id);
        String xlxBm = qrCodeMapper.getQyXlxBm(qr_id);

        poleEquipmentDto.setQybm(qyName);
        poleEquipmentDto.setXlxbm(xlxBm);
        poleEquipmentDto.setQdsxjDtoList(qdsxjList);

        List<String> buttonPrivileges = userService.getUserButtonPrivilegeList(user.getUser_id(), Constants.PRIVILEGE_CODE_WORK_MENU);
        Integer approveWorkRight = 0;
        if (!CollectionUtils.isEmpty(buttonPrivileges) && buttonPrivileges.contains("work:approve")) {
            approveWorkRight = 1;   // 有完成工单的权限
        }
        poleEquipmentDto.setApproveWorkRight(approveWorkRight);

        // 杆件未处理工单列表
        List<Work> works = workMapper.getUnhandledWorkListByPoleId(jkgw.getGw_id());
        if (CollectionUtils.isEmpty(works)) {
            return poleEquipmentDto;
        }
        List<WorkInfoDto> poleUnhandledWorkDtoList = new ArrayList<>();
        works.forEach(work -> {
            WorkInfoDto workInfoDto = workService.assembleWorkInfoDto(work);
            poleUnhandledWorkDtoList.add(workInfoDto);
        });
        poleEquipmentDto.setWorkInfoDtoList(poleUnhandledWorkDtoList);


        return poleEquipmentDto;
    }

    @Override
    public List<ScwgtEquipDto> getScwgtPoleEquipList(int poleId) {
        List<ScwgtEquipDto> equipDtoList = new ArrayList<>();
        List<Integer> equipIds = equipmenMapper.findByGwID(poleId);
        if (CollectionUtils.isEmpty(equipIds)) {
            logger.info("getScwgtPoleEquipList: find equip list empty. poleId={}", poleId);
            return equipDtoList;
        }

        equipIds.forEach(equipId -> {
            Qdsxj equip = qdsxjMapper.getById(equipId);
            ScwgtEquipDto equipDto = new ScwgtEquipDto();
            equipDto.setSb_id(equip.getSb_id());
            equipDto.setGb_id(equip.getSb_bm());
            equipDto.setSb_name(equip.getSb_name());
            equipDtoList.add(equipDto);
        });

        return equipDtoList;
    }

    @Override
    public Jkgw getByLatAndLng(Integer qrId) {
        return jkgwMapper.getByLatAndLng(qrId);
    }

    @Override
    public Jkgw getByIdMD5(String qrIdMD5) {
        return jkgwMapper.getByIdMD5(qrIdMD5);
    }

    @Override
    public int updateJkgwPoleDto(PoleDto poleDto) {
        return jkgwMapper.updateJkgwPoleDto(poleDto);
    }

    /**
     * 根据经纬度和半径搜索设备和杆位
     *
     * @param map
     * @return
     */
    @Override
    public Jkgw getBoleByIdLatitudeAndRadius(Map<String, Object> map) {
        String gw_jd = String.valueOf(map.get("longitude"));
        String gw_wd = String.valueOf(map.get("latitude"));
        return jkgwMapper.getBoleByIdLatitudeAndRadius(gw_jd, gw_wd);
    }

    /**
     * @return
     * @Author liuzhengli
     * @Description //TODO  根据杆位对象获取所有杆位
     * @Date 2021/8/9 0009 20:45
     * @Param * @param null:
     */
    @Override
    public List<Jkgw> getJkgwList(Jkgw jkgw) {
        return jkgwMapper.getJkgwList(jkgw);
    }

    @Override
    public Page<Jkgw> getInfo(Integer pageNo, Integer pageSize, String begintime, String endtime, String badw, String gw_name) {
        Page<Jkgw> page = new Page<>(pageNo, pageSize);
        PageUtils.startPage();
        List<Jkgw> list = jkgwMapper.getInfo(begintime, endtime, badw, page, gw_name);
        if (!CollectionUtils.isEmpty(list)) {
            list.forEach(jkgw -> {
                jkgw.setLongitude(NumberUtil.formatNumber(jkgw.getGw_jd()));
                jkgw.setLatitude(NumberUtil.formatNumber(jkgw.getGw_wd()));
            });
        }
        page.setTotal(new PageInfo<>(list).getTotal());
        return page.setRecords(list);
    }

    @Override
    public List<Jkgw> getByPositionAndRadius(double longitude, double latitude, double radius) {
        return jkgwMapper.getPolesByPositionAndRadius(longitude, latitude, radius);
    }

    @Override
    public List<PoleDto> searchByPositionAndRadius(double longitude, double latitude, double radius) {
        List<PoleDto> poleDtos = new ArrayList<>();
        List<Jkgw> jkgwList = jkgwMapper.getPolesByPositionAndRadius(longitude, latitude, radius);
        if (CollectionUtils.isEmpty(jkgwList)) {
            return poleDtos;
        }
        jkgwList.forEach(pole -> {
            PoleDto poleDto = assemblePoleDto(pole);
            List<PoleQrCodeBindHistory> bindHistoryList = poleQrCodeBindHistoryMapper.getByPoleId(pole.getGw_id());
            if (!CollectionUtils.isEmpty(bindHistoryList)) {
                poleDto.setQrCodeChangeCount(bindHistoryList.size());
            }

            List<EquipBindingWork> equipBindingWorkList = equipBindingWorkMapper.getByPoleIdAndState(pole.getGw_id(), Constants.EQUIP_BINDING_WORK_STATE_NOT_HANDLED);
            if (!CollectionUtils.isEmpty(equipBindingWorkList) && tempEquipBindingWorkFilterProperties.getPoleIdList().contains(poleDto.getGw_id())) {
                poleDto.setUnhandledEuipWorkCount(equipBindingWorkList.size());
            }
            poleDtos.add(poleDto);
        });
        return poleDtos;
    }

    @Override
    public PoleDto findPole(int poleId) {
        Jkgw pole = jkgwMapper.getById(poleId);
        if (Objects.isNull(pole)) {
            return null;
        }

        PoleDto poleDto = new PoleDto();
        poleDto = assemblePoleDto(pole);
        List<PoleQrCodeBindHistory> bindHistoryList = poleQrCodeBindHistoryMapper.getByPoleId(poleId);
        if (!CollectionUtils.isEmpty(bindHistoryList)) {
            poleDto.setQrCodeChangeCount(bindHistoryList.size());
        }
        List<EquipBindingWork> equipBindingWorkList = equipBindingWorkMapper.getByPoleIdAndState(pole.getGw_id(), Constants.EQUIP_BINDING_WORK_STATE_NOT_HANDLED);
        if (!CollectionUtils.isEmpty(equipBindingWorkList) && tempEquipBindingWorkFilterProperties.getPoleIdList().contains(poleDto.getGw_id())) {
            poleDto.setUnhandledEuipWorkCount(equipBindingWorkList.size());
        }

        return poleDto;
    }

    @Override
    public List<Jkgw> getAll() {
        return jkgwMapper.getAllPoles();
    }

    @Override
    public int updateAreaCodeAndTownCode(int poleId, String areaCode, String areaName, String townCode, String townName) {
        return jkgwMapper.updateAreaCodeAndTownCode(poleId, townCode, townName, areaCode, areaName);
    }

    /**
     * 替换二维码操作:
     * 1）更新新二维码的区域编码、小类型编码、20编码
     * 1) 更新杆件二维码和20编码
     * 2）更新设备绑定表二维码id
     *
     * @param poleId
     * @param oldQrCodeMd5
     * @param newQrCodeMd5
     */
    @Transactional
    @Override
    public void changeBindQrCode(int poleId, String oldQrCodeMd5, String newQrCodeMd5) {
        Jkgw jkgw = jkgwMapper.getById(poleId);

        QRCode oldQrCode = qrCodeMapper.getByIdMD5(oldQrCodeMd5);
        QRCode newQrCode = qrCodeMapper.getByIdMD5(newQrCodeMd5);
        if (oldQrCode == null) {
            newQrCode.setQr_bm(jkgw.getGw_bm());
        } else {
            String qrCodeBm = String.format("%s-%s-%s", oldQrCode.getQybm(), oldQrCode.getXlxbm(), newQrCode.getXh());
            newQrCode.setQr_bm(qrCodeBm);
            newQrCode.setXlxbm(oldQrCode.getXlxbm());
            newQrCode.setQybm(oldQrCode.getQybm());
        }
        qrCodeMapper.updateQRCodeBm(newQrCode.getQr_id(), newQrCode.getQybm(), newQrCode.getXlxbm(), newQrCode.getQr_bm());

        jkgwMapper.updateQrIdMd5(poleId, oldQrCodeMd5, newQrCodeMd5, newQrCode.getQr_bm());
        logger.info("changeBindQrCode: update QrIdMd5: poleId={}, oldQrCode={}, newQrCode ={}", poleId, oldQrCodeMd5, newQrCodeMd5);
        List<Equipmen> equipmenList = equipmenMapper.getByGwid(poleId);
        if (!CollectionUtils.isEmpty(equipmenList)) {
            equipmenMapper.updateQrId(poleId, newQrCode.getQr_id());
            logger.info("changeBindQrCode: update equipmen qrid: poleId={}, oldQrId={}, newQrId={}", poleId, equipmenList.get(0).getEq_id(), newQrCode.getQr_id());
        }
    }

    @Override
    public int saveChangeBindHistory(int poleId, String oldQrCodeMd5, String newQrCodeMd5, int changeType, int tempUserId) {
        PoleQrCodeBindHistory poleQrCodeBindHistory = new PoleQrCodeBindHistory();
        poleQrCodeBindHistory.setPole_id(poleId);
        poleQrCodeBindHistory.setOld_qrid_md5(oldQrCodeMd5);
        poleQrCodeBindHistory.setNew_qrid_md5(newQrCodeMd5);
        poleQrCodeBindHistory.setChange_bind_type(changeType);
        poleQrCodeBindHistory.setTmp_user_id(tempUserId);
        return poleQrCodeBindHistoryMapper.insert(poleQrCodeBindHistory);
    }

    @Override
    public int saveChangeBindHistory(PoleQrCodeBindHistory poleQrCodeBindHistory) {
        return poleQrCodeBindHistoryMapper.insert2(poleQrCodeBindHistory);
    }

    @Override
    public List<PoleQrCodeBindHistory> getQrCodeBindHistory(String newQrCodeMd5) {
        return poleQrCodeBindHistoryMapper.getByNewQrIdMd5(newQrCodeMd5);
    }

    private Jkgw assembleJkgw(PoleDto poleDto) {
        Jkgw jkdw = new Jkgw();
        jkdw.setGw_zx(poleDto.getGw_zx());
        jkdw.setGw_bw(poleDto.getGw_bw());
        jkdw.setGw_jd(poleDto.getGw_jd());
        jkdw.setGw_wd(poleDto.getGw_wd());
        jkdw.setGw_name(poleDto.getGw_name());
        jkdw.setGw_wz(poleDto.getGw_wz());
        //String qrCodeBm = String.format("%s-%s-%s", poleDto.getGw_xzqy(), poleDto.getGw_type(),qrCode.getXh());
        System.err.println(poleDto.getGw_bm());
        jkdw.setGw_bm(poleDto.getGw_bm());
        jkdw.setQrid_md5(poleDto.getQrid_md5());
        jkdw.setTown_code(poleDto.getTown_code());
        jkdw.setTown_name(poleDto.getTown_name());
        jkdw.setArea_code(poleDto.getArea_code());
        jkdw.setArea_name(poleDto.getArea_name());
        return jkdw;
    }

    private PoleDto assemblePoleDto(Jkgw jkgw) {
        PoleDto poleDto = new PoleDto();
        poleDto.setGw_id(jkgw.getGw_id());
        poleDto.setGw_bm(jkgw.getGw_bm());
        poleDto.setQrid_md5(jkgw.getQrid_md5());
        poleDto.setArea_code(jkgw.getArea_code());
        poleDto.setArea_name(jkgw.getArea_name());
        poleDto.setGw_bw(jkgw.getGw_bw());
        poleDto.setGw_jd(jkgw.getGw_jd());
        poleDto.setGw_wd(jkgw.getGw_wd());
        poleDto.setGw_name(jkgw.getGw_name());
        poleDto.setGw_wz(jkgw.getGw_wz());
        poleDto.setGw_zx(jkgw.getGw_zx());
        poleDto.setModify_time(jkgw.getModify_time());
        poleDto.setTown_code(jkgw.getTown_code());
        poleDto.setTown_name(jkgw.getTown_name());
        poleDto.setWait_check(jkgw.getWait_check());
        return poleDto;
    }

}
